package sort;

public class InsertSort {

    //把比插入的数小的数向后移，再把数插到空出位置
    public static void main(String args[]) {

        int arr[] = new int[]{123, 4, 5, 67, 7, 8, 54, 2, 43, 452, 3423, 452, 34, 5, 7, 87857, 32};

        for (int i = 1; i < arr.length; i++) {
            int val = arr[i];
            int j = i - 1;
            while (j >= 0 && arr[j] > val) {
                arr[j + 1] = arr[j];
                j--;
            }
            arr[j + 1] = val;
        }

        for (int i : arr)
            System.out.println(i);
    }
}
